package practice2;

import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.Scanner;

public class Client {
    public static void main(String[] args) throws IOException {
        Socket socket = new Socket("192.168.43.82",10086);
        OutputStream os = socket.getOutputStream();
        Scanner sc = new Scanner(System.in);

        // 发送数据
        while (true) {
            System.out.println("请输入你要发送的数据");
            String str = sc.nextLine();
            if("886".equals(str)){
                // 写出一个结束标记
                socket.shutdownOutput();
                break;
            }
            os.write(str.getBytes());
        }

        // 接受数据
        InputStream is = socket.getInputStream();
        InputStreamReader isr = new InputStreamReader(is);
        int b = 0;
        while((b = isr.read()) != -1){
            System.out.print((char)b);
        }

        // 释放资源
        socket.close();
    }
}
